home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
0391B.ZIP
/
KEYDEFS.ARC
/
KEYDEMO.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1986-03-11
|
5KB
|
165 lines
{***********************************************
* *
* Keyboard Definitions Demonstration Program *
* *
* by Richard R. Rebouche *
* *
* UpDate: 03/10/86 *
* *
***********************************************}
{$I Keydefs.Inc}
{*****************************************************
* *
* Global Constant, Type, and Variable declarations *
* *
*****************************************************}
Const Term_Height = 25;
Term_Width = 80;
Type Str02 = String[02];
Var C, Window_Top, Line_Count : Integer;
{*************************************
* *
* Utility Functions and Procedures *
* *
*************************************}
{ Function: Return a byte value as two hexadecimal digits. }
Function Hex_Value (N : Byte) : Str02;
Const H : Array [0..15] of Char = '0123456789ABCDEF';
Begin
Hex_Value := H[N Div 16] + H[N Mod 16];
End;
{ Procedure: Print the introductory text for the demonstration. }
Procedure Print_Intro;
Begin
WriteLn;
WriteLn ('*** Key Definition Demo ***');
WriteLn;
WriteLn ('Enter special keys (like Alt-F1) from the keyboard.');
WriteLn ('The program will print the token returned and a');
WriteLn ('description of the key that was pressed.');
WriteLn;
WriteLn ('Press the ESCAPE key to stop the program.');
WriteLn;
WriteLn;
Line_Count := 11; { 10 Lines + 1 to compensate for behavior at line #25 }
End;
{ Procedure: Print a description of a key based on its token value. }
{ Under normal circumstances one would not need (or want) }
{ to implement key trapping on this scale. }
Procedure Print_Key_Desc (I : Integer);
Type Template = Array [1..12] of Char;
Const Row_1 : Template = '1234567890-='; { These are for the ALT-char }
Row_2 : Template = 'QWERTYUIOP '; { types of keystrokes }
Row_3 : Template = 'ASDFGHJKL ';
Row_4 : Template = 'ZXCVBNM ';
Begin
Case I of
Esc_Key : Write ('Escape Key');
Tab_Key : Write ('Tab Key');
Shft_Tab : Write ('Shifted Tab Key');
Back_Del : Write ('Back Arrow');
Return : Write ('Return Key');
Space : Write ('Space Bar');
Ins_Key : Write ('Insert Key');
Del_Key : Write ('Delete Key');
Home_Key : Write ('Home Key');
Ctrl_Home : Write ('Control Home');
End_Key : Write ('End Key');
Ctrl_End : Write ('Control End');
PgUp : Write ('Page Up Key');
Ctrl_PgUp : Write ('Control Page Up');
PgDn : Write ('Page Down Key');
Ctrl_PgDn : Write ('Control Page Down');
Up_Key : Write ('Up Arrow');
Down_Key : Write ('Down Arrow');
Left_Key : Write ('Left Arrow');
Ctrl_Left : Write ('Control Left Arrow');
Right_Key : Write ('Right Arrow');
Ctrl_Right : Write ('Control Right Arrow');
0..31 : Write ('Control "', Chr(I+64), '"');
32..255 : Write ('Character "', Chr(I), '"');
F1..F10 : Write ('Function ' , I - F1 + 1);
Shft_F1..Shft_F10 : Write ('Shift Function ' , I - Shft_F1 + 1);
Ctrl_F1..Ctrl_F10 : Write ('Control Function ' , I - Ctrl_F1 + 1);
Alt_F1..Alt_F10 : Write ('Alternate Function ', I - Alt_F1 + 1);
Alt_1..Alt_Equal : Write ('Alternate ', Row_1[I - Alt_1 + 1]);
Alt_Q..Alt_P : Write ('Alternate ', Row_2[I - Alt_Q + 1]);
Alt_A..Alt_L : Write ('Alternate ', Row_3[I - Alt_A + 1]);
Alt_Z..Alt_M : Write ('Alternate ', Row_4[I - Alt_Z + 1]);
Else Write ('An unidentified special key.');
End;
End;
{**********************
* *
* Main program body *
* *
**********************}
Begin
Print_Intro; { Display introductory text and }
C := 0; { initialize variables/counters }
Window_Top := Line_Count;
While C <> Esc_Key do { Loop until user presses ESCAPE }
Begin
Write ('Press a Key: '); { Read the keystroke }
C := GetKey;
Write ('$', Hex_Value(Hi(C)), Hex_Value(Lo(C))); { Echo back to user }
Write (' Description: ');
Print_Key_Desc(C);
WriteLn;
Line_Count := Line_Count + 1; { Window to keep the }
If Line_Count = Term_Height then { text on the screen }
Window (1, Window_Top, Term_Width, Term_Height);
End;
End.